<extend name="./public/frame.html"/>
<block name="content">
	<div class="layui-row">
		<div class="layui-inline">
			<?php if($admin_info['admin_type'] == 1):?>
			<select id="all_order" name="all_order" class="layui-input" style="width: 90px;">
				<option value="">全部订单</option>
				<option value="1">普通订单</option>
				<option value="2">测试订单</option>
			</select>
		</div>
		<?php endif;?>
		<div class="layui-inline">
			<select name="province" lay-filter="province_id" id="province_id" class="layui-input" style="width: 120px;" onchange="provinceChange();">
				<option value="">请选择省份</option>
				<volist name="province" id="vo">
				<option value="{$vo['region_id']}">{$vo['region_name']}</option>
				</volist>
			</select>
		</div>
		<div class="layui-inline">
			<select name="city" lay-filter="city_id" id="city_id" class="layui-input" style="width: 120px;">
				<option value="">请选择城市</option>
			</select>
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="type" class="layui-input" style="width: 120px;">
				<option value="1">下单时间</option>
				<option value="2">出发时间</option>
			</select>
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input date" readonly id="start" placeholder="开始时间" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input date" readonly id="end" placeholder="结束时间" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="start_arean" class="layui-input" style="width: 120px;">
				<option value="">出发城市</option>
				<volist name="arean" id="v">
					<option value="{$v['id']}">{$v['name']}</option>
				</volist>
			</select>
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="end_arean" class="layui-input"  style="width: 120px;">
				<option value="">到达城市</option>
				<volist name="arean" id="v">
					<option value="{$v['id']}">{$v['name']}</option>
				</volist>
			</select>
		</div>
		<div class="layui-inline">
			<input type="text" lay-verify="required|title" required placeholder="请输入订单号"  class="layui-input" id="order_sn" style="width: 200px;">
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="type_phone" class="layui-input" style="width: 120px;">
				<option value="1">司机手机号</option>
				<option value="2">乘客手机号</option>
			</select>
		</div>
		<div class="layui-inline">
			<input type="text" lay-verify="required|title" required placeholder="请输入手机号"  class="layui-input" id="phone" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<input type="text" lay-verify="required|title" required placeholder="请输入车牌号"  class="layui-input" id="car_plate" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="order_status" class="layui-input" style="width: 150px;">
				<option value="">订单状态</option>
				<volist name="order_status" id="status">
					<option value="{$key}">{$status}</option>
				</volist>
			</select>
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="pay_type" class="layui-input" style="width: 120px;margin-top: 3px;">
				<option value="">付款方式</option>
				<volist name="pay_type" id="type">
					<option value="{$key}">{$type}</option>
				</volist>
			</select>
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="is_pay" class="layui-input" style="width: 120px;margin-top: 3px;">
				<option value="">付款状态</option>
				<volist name="is_pay" id="type">
					<option value="{$key}">{$type}</option>
				</volist>
			</select>
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="fleet_id" class="layui-input" style="width: 120px;margin-top: 3px;">
				<option value="">所属车队</option>
				<volist name="fleet_list" id="vo">
					<option value="{$vo['id']}">{$vo['name']}</option>
				</volist>
			</select>
		</div>
		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="is_contract" class="layui-input" style="width: 120px;margin-top: 3px;">
				<option value="">是否包车</option>
				<volist name="is_contract" id="vo">
					<option value="{$key}">{$vo}</option>
				</volist>
			</select>
		</div>
		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
			<button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
			<button class="layui-btn layui-btn-warm" data-type="excel">导出数据</button>
		</div>
		* <span style="color: green">乘客手机号为红色 - 测试用户 / 司机手机号为红色 - 测试司机</span>
	</div>
	<table class="layui-table" lay-filter="order" id="order"></table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="detail">详细</a>
		{{#if(d.status==0||d.status==30||d.status==35||d.status==36||d.status==37||d.status==38||d.status==40){}}
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="cancel">取消</a>
		{{#}else{}}
		<a class="layui-btn layui-btn-xs layui-btn-disabled">取消</a>
		{{#}}}
		<?php if($_SESSION['admin_id'] == 1){ ?>
		<a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
		<?php } ?>
		{{#if(d.secret_no_bind_status == 1){}}
		<a class="layui-btn layui-btn-xs" lay-event="sound">查看录音</a>
		{{#}}}
	</script>
	<script type="text/html" id="statusTpl">
		{{#if(d.status==0){}}
		<span style="color: grey">{{d.order_status}}</span>
		{{#}else if(d.status==10 || d.status==11){}}
		<span style="color: red">{{d.order_status}}</span>
		{{#}else if(d.status==12){}}
		<span style="color: red">{{d.order_status}}</span>
		{{#}else if(d.status==15){}}
		<span style="color: red">{{d.order_status}}</span>
		{{#}else if(d.status==16){}}
		<span style="color: red">{{d.order_status}}</span>
		{{#}else if(d.status==20){}}
		<span style="color: green">{{d.order_status}}</span>
		{{#}else if(d.status==25){}}
		<span style="color: darkorange">{{d.order_status}}</span>
		{{#}else if(d.status==30){}}
		<span style="color: seagreen">{{d.order_status}}</span>
		{{#}else if(d.status==35){}}
		<span style="color: skyblue">{{d.order_status}}</span>
		{{#}else if(d.status==37){}}
		<span style="color: skyblue">{{d.order_status}}</span>
		{{#}else if(d.status==40){}}
		<span style="color: deepskyblue">{{d.order_status}}</span>
		{{#}else if(d.status==45){}}
		<span style="color: slateblue">{{d.order_status}}</span>
		{{#}else{}}
		<span style="color: fuchsia">{{d.order_status}}</span>
		{{#}}}
	</script>

	<script type="text/html" id="ispayTpl">
	{{#if(d.is_pay==0){}}
	<span style="color: red">未付款</span>
	{{#}else if(d.is_pay==1){}}
	<span style="color: seagreen">已付款</span>
	{{#}}}
	</script>
	 <!--<script type="text/html" id="phoneTpl">-->
		<!--{{#if(d.is_ceshi==1){}}-->
		 <!--<span style="color: red">{{d.user_phone}}</span> -->
		<!--{{#}else{}}-->
		<!--<span >{{d.user_phone}}</span>-->
		<!--{{#}}}-->
	<!--</script>-->
	<script type="text/html" id="userTpl">
		{{#if(d.user_type == 1) { }}
		<span style="color: red">{{d.user_phone}}</span>
		{{# } else { }}
		{{d.user_phone}}
		{{#}}}
	</script>
	<script type="text/html" id="driverTpl">
		{{#if(d.driver_type == 1) { }}
		<span style="color: red">{{d.driver_phone}}</span>
		{{# } else { }}
		{{d.driver_phone}}
		{{#}}}
	</script>
	<script type="text/html" id="paytoolTpl">
		{{#if(d.paytool == 1) { }}支付宝
		{{# } else if (d.paytool == 2) { }}微信
		{{# } else { }}余额
		{{#}}}
	</script>
	<script type="application/javascript">
		layui.use(['table', 'laytpl', 'laydate','form'], function () {
			var table = layui.table
				, form = layui.form
				, laydate = layui.laydate;

			lay('.date').each(function(){
				laydate.render({
					elem: this
					,type: 'date'
					,trigger: 'click'
				});
			});
			var tableIns = table.render({
				elem:"#order",
				url:"{$url}",
				cols: [[
//					{checkbox:true,title:"",fixed: true},
					{field:'id',title:"ID", width:80,sort: true,fixed:'left',align:'center'},
                    {field:'area',title:"省/市/区", width:200,sort: true,align:'center'},
//                    {field:'city_name',title:"市", width:100,sort: true},
					{field:'order_sn',title:"订单号", width:190,sort: true,align:'center'},
//                    {field:'member_id',title:"用户UID", width:100,sort: true},
                    {field:'user_phone',title:"下单人手机号", width:130,sort: true,align:'center',templet:'#userTpl'},
                    {field:'start_name',title:"出发地", width:190,sort: true,align:'center'},
                    {field:'arrive_name',title:"目的地", width:190,sort: true,align:'center'},
					{field:'passenger',title:"乘客数", width:100,sort: true,align:'center'},
					{field:'start_time',title:"预约出发时间", width:190,sort: true,align:'center'},
                    {field:'contact_number',title:"联系人号码", width:120,sort: true,align:'center'},
					{field:'order_time',title:"下单时间", width:160,sort: true,align:'center'},
                    {field:'is_contract',title:"是否包车", width:90,align:'center'},
                    {field:'order_price',title:"价格(元)", width:120,align:'center'},
                    {field:'driver_name',title:"司机姓名", width:100,sort: true,align:'center'},
                    {field:'driver_phone',title:"司机手机号", width:120,sort: true,align:'center',templet:'#driverTpl'},
                    {field:'car_plate',title:"车牌号", width:100,align:'center'},
                    {field:'paytool',title:"付款方式", width:100,align:'center',templet:'#paytoolTpl'},
					{field:'fleet_name',title:"所属车队", width:150,sort: true,align:'center',fixed:'right'},
                    {field:'order_status',title:"订单状态", width:150,templet:'#statusTpl',sort: true,align:'center',fixed:'right'},
                    {field:'is_pay',title:"支付状态", width:100,templet:'#ispayTpl',fixed:'right',align:'center'},

//					{field:'order_time',title:"下单时间", width:160,sort: true},
//					{field:'start_time',title:"出发时间", width:160,sort: true},
//					{field:'ban',title:"订单班次", width:120},
//					{field:'user_phone',title:"下单用户", width:120,templet:'#phoneTpl'},
//                  {field:'coupon_price',title:"优惠金额", width:80},
					{title:"操作",toolbar: '#barDemo',width:240,fixed:'right',align:'center'}
				]],
				page:true,
				limit:10,
				done: function(res, curr, count){
					_cur_page =curr;
					_cur_limit =res['limit'];
				}
			});
			//监听工具条
			table.on('tool(order)', function (obj) {
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
				var tr = obj.tr; //获得当前行 tr 的DOM对象
				var id = data.id;
				var status = data.status;
				if (layEvent === 'detail'&&(status==30||status==35)) {
					layer.open({
						type: 2,
						title: '订单'+data.order_sn+'的信息',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/inter_order/detail","common_id=")}' + id, //iframe的url
						cancel: function (index, layero) {
							tableIns.reload("{$url}");
						}
					});
				}
				else if (layEvent === 'detail'&&(status!=30&&status!=35)) {
					layer.open({
						type: 2,
						title: '订单'+data.order_sn+'的信息',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/inter_order/detail","common_id=")}' + id, //iframe的url
					});
				}
				else if (layEvent === 'delete') {
					var obj = this;
					layer.confirm('确定删除', function(index){
						$.post('/admin/inter_order/interOrderDel',{id:id},function (res) {
							switch (res['code']){
								case 1:
									layer.msg(res['msg'],{icon:1});
									   console.log($(obj).parent().parent().parent());
								  $(obj).parent().parent().parent().hide();

									break;
								default:
									layer.msg(res['msg'],{icon: 5});
									break;
							}
						},'json');
					  layer.close(index);
					});
				}
				else if(layEvent === 'cancel'){
					layer.prompt({title: '请输入取消原因', formType: 2}, function(text, index){
						layer.close(index);
						$.post('/admin/inter_order/cancel',{id:id,cancel_reason:text},function (res) {
							switch (res['status']){
								case 1:
									layer.alert(res['msg'],{icon:1},function (index) {
										window.location.reload();
									});
									break;
								default:
									layer.alert(res['msg'],{icon: 5});
									break;
							}
						},'json');
					});
				}
                else if (layEvent === 'sound') { //查看录音
                    layer.open({
                        type: 2,
                        title: '订单'+data.order_sn+'的录音记录',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['800px', '500px'],
                        content: '{:url("/admin/inter_order/sound","common_id=")}' + id + "&order_type=3", //iframe的url order_type 1快车  3城际 4顺风车
                    });
                }
			});

			var $ = layui.jquery, active = {
				search: function () {
					var province_id = $('#province_id').val(),
                        city_id = $('#city_id').val(),
						type = $('#type').val(),
						start = $('#start').val(),
						end = $('#end').val(),
                        start_arean = $("#start_arean").val(),
                        end_arean = $("#end_arean").val(),
						order_sn = $.trim($('#order_sn').val()),
						type_phone = $('#type_phone').val(),
                        phone = $.trim($('#phone').val()),
						order_status = $('#order_status').val(),
						car_plate = $.trim($('#car_plate').val()),
						pay_type = $('#pay_type').val(),
						is_pay = $('#is_pay').val(),
                        fleet_id = $('#fleet_id').val(),
                        is_contract = $('#is_contract').val(),
						all_order = $('#all_order').val(),
						reset = $('#reset');
					if(province_id||city_id||start||end||start_arean||end_arean||order_sn||phone||order_status||car_plate||pay_type||is_pay||fleet_id||is_contract||all_order){
						reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
						tableIns.reload({
							url: '/admin/inter_order/search',
							where: {
                                province_id : province_id,
								city_id : city_id,
								type :type,
								start : start,
								end : end,
                                start_arean : start_arean,
                                end_arean : end_arean,
								order_sn : order_sn,
                                type_phone : type_phone,
                                phone : phone,
								order_status : order_status,
								car_plate : car_plate,
								pay_type : pay_type,
								is_pay : is_pay,
								fleet_id : fleet_id,
                                is_contract:is_contract,
								all_order:all_order
							} //设定异步数据接口的额外参数
						});
					}else{
						reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
						layer.alert('搜索项不能为空');
					}
				}
				, reset: function () {
					var reset = $('#reset');
					if (reset.data('type') !== '') {
						tableIns.reload({
							url: '/admin/inter_order/table', where:{}
						});
					}
					$('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
					reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
				}
				, excel: function () {
                    var province_id = $('#province_id').val(),
                        city_id = $('#city_id').val(),
                        type = $('#type').val(),
                        start = $('#start').val(),
                        end = $('#end').val(),
                        start_arean = $("#start_arean").val(),
                        end_arean = $("#end_arean").val(),
                        order_sn = $.trim($('#order_sn').val()),
                        type_phone = $('#type_phone').val(),
                        phone = $.trim($('#phone').val()),
                        order_status = $('#order_status').val(),
                        car_plate = $.trim($('#car_plate').val()),
                        pay_type = $('#pay_type').val(),
						all_order = $('#all_order').val(),
                        is_pay = $('#is_pay').val();
                        fleet_id = $('#fleet_id').val();
                        is_contract = $('#is_contract').val();
					var str = "&phone="+ phone + "&type=" + type + "&all_order=" + all_order +"&start="
						+ start + "&end=" + end + "&order_status=" + order_status+ "&pay_type=" + pay_type
						+ "&car_plate=" + car_plate + "&start_arean=" + start_arean + "&end_arean=" + end_arean + "&province_id=" + province_id + "&city_id=" + city_id + "&order_sn=" + order_sn+ "&type_phone=" + type_phone + "&is_pay=" + is_pay + "&fleet_id=" + fleet_id + "&is_contract=" + is_contract;
					layer.confirm('请选择导出内容:', {
						btn: ['全部数据', '当前页', '取消'] //可以无限个按钮
						, btn3: function (index, layero) {
							layer.close(index);
						}
					}, function (index, layero) {
						//按钮【按钮一】的回调
						location = "{:url('excel','all=1')}"+str ;
						layer.close(index);
					}, function (index) {
						location = "{:url('excel','all=2')}" + str+"&page="+_cur_page+"&limit="+_cur_limit;
						layer.close(index);
					});
				}
			};
			$('.layui-btn').on('click', function () {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
		});

		function provinceChange() {
            var province_id = $("#province_id").val();
            if(province_id === 0) {
				$("#city_id").empty();
				$("#city_id").append('<option value=>请选择城市</option>');
				return false;
			}

            $.ajax({
                type: 'POST',
                url: "{:url('/admin/Franchisee/cityList')}",
                data: {'province_id':province_id},
//                dataType:  'json',
                success:function(res){
                    $("select[name='city']").empty();
                    $("#city_id").append("<option value=''>全部城市</option>" + res);
                },
				error:function (res) {
                    layer.msg('请求错误');return false;
                }
            });
		}

	</script>
</block>
